package com.keyinong.caizhengting.activity;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.keyinong.caizhengting.R;

/**
 * @author：郑谦
 * @时间：2017-4-10 下午4:02:27
 * @类名：MysetActivity.java
 * @功能: 个人中心-设置
 */
public class MysetActivity extends Activity {
    View iscatview = null;
    private ImageView ib_fanhui;
    /**
     * 修改密码
     */
    private RelativeLayout rl_xiugai;
    /**
     * 退出登录
     */
    private RelativeLayout rl_tuichu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            // 透明状态栏
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            // 透明导航栏
//			getWindow().addFlags(
//					WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        setContentView(R.layout.activity_myset);
        initRes();
    }

    private void initRes() {
        ib_fanhui = (ImageView) findViewById(R.id.ib_fanhui);
        ib_fanhui.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
            }
        });
        rl_xiugai = (RelativeLayout) findViewById(R.id.rl_xiugai);
        rl_xiugai.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MysetActivity.this, UpdatepwdActivity.class);
                startActivity(intent);
                finish();
            }
        });
        rl_tuichu = (RelativeLayout) findViewById(R.id.rl_tuichu);
        rl_tuichu.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
//				Intent intent = new Intent(MysetActivity.this,LoginActivity.class);
//				startActivity(intent);
//				finish();
                tuichudialog();
            }
        });

    }

    /**
     * 退出弹窗
     */
    private void tuichudialog() {

        final Dialog dialog = new Dialog(MysetActivity.this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

        iscatview = LayoutInflater.from(MysetActivity.this).inflate(
                R.layout.dialog_pay, null);
        TextView tital = (TextView) iscatview.findViewById(R.id.tital);
        TextView tv_no = (TextView) iscatview.findViewById(R.id.tv_no);
        TextView tv_yes = (TextView) iscatview.findViewById(R.id.tv_yes);
        tital.setText("是否退出登录?");
        dialog.setContentView(iscatview);
        dialog.show();
        tv_no.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                //				Intent intent = new Intent();
                //				intent.putExtra("price", total);
                //				intent.putExtra("orderid", id);
                //				intent.setClass(DingdandetailActivity.this, BalancepayActivity.class);
                //				startActivity(intent);
                dialog.dismiss();
            }
        });
        tv_yes.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                SharedPreferences spuser = getSharedPreferences(
                        "spuser", Context.MODE_PRIVATE);
                Editor spusereditor = spuser.edit();
                spusereditor.clear();
                spusereditor.commit();

                SharedPreferences sp = getSharedPreferences(
                        "spReg", Context.MODE_PRIVATE);
                Editor editor = sp.edit();
                editor.clear();
                editor.commit();
                Intent logIntent = new Intent(MysetActivity.this,
                        LoginActivity.class);
                startActivity(logIntent);
                finish();
                dialog.dismiss();
            }
        });
    }


}
